<template>
  <div>
    <div class="lunbo">
      <div class="picture">
        <ul class="pic">
          <li class="item active"><img src="@/assets/img/1.png" alt="" /></li>
          <li class="item"><img src="@/assets/img/2.png" alt="" /></li>
          <li class="item"><img src="@/assets/img/3.png" alt="" /></li>
        </ul>
        <ul class="lib">
          <li class="point active" data-index="0"></li>
          <!--data-index为了使点击此处时得出对应的index值-->
          <li class="point" data-index="1"></li>
          <li class="point" data-index="2"></li>
        </ul>
        <button type="button" class="btn" id="goPre">&lt</button>
        <button type="button" class="btn" id="goNext">&gt</button>
      </div>
    </div>
    <div>
      <div class="mid">
        <img src="@/assets/img/lub-1.png" alt="" />
        <img src="@/assets/img/lub-2.png" alt="" />
      </div>
      <div class="cont">
        <div style="margin-top:80px"><h3 class="tco1">制定一个学习计划，每天完成一点</h3></div>
        <div>
          <h3 class="tco2">
            只有不断前进，才能收获更多，只有不断努力，才能走的更远
          </h3>
        </div>
      </div>
      <div class="footer">
        <img src="@/assets/img/lub-3.png" alt="" />
        <img src="@/assets/img/lub-4.png" alt="" />
        <img src="@/assets/img/lub-5.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  mounted() {
    //左右按钮实现
    var items = document.getElementsByClassName('item')
    var points = document.getElementsByClassName('point')
    var goPrebtn = document.getElementById('goPre')
    var goNextbtn = document.getElementById('goNext')

    var index = 0

    var clearActive = function () {
      //初始化使改变每张图片classname
      for (var i = 0; i < items.length; i++) {
        items[i].className = 'item'
      }
      for (var i = 0; i < items.length; i++) {
        points[i].className = 'point'
      }
    }
    var goIndex = function () {
      //给下标为index的改变classname
      clearActive()
      items[index].className = 'item active'
      points[index].className = 'point active'
    }
    var gonext = function () {
      if (index < 2) {
        index++
      } else {
        index = 0
      }
      goIndex()
    }
    goNextbtn.addEventListener('click', function () {
      //点击事件
      gonext()
    })
    var gopre = function () {
      if (index == 0) {
        index = items.length - 1
      } else {
        index--
      }
      goIndex()
    }
    goPrebtn.addEventListener('click', function () {
      //点击事件
      gopre()
    })

    //小圆点实现
    for (var i = 0; i < points.length; i++) {
      points[i].addEventListener('click', function () {
        var pointIndex = this.getAttribute('data-index') //获取对应index值
        index = pointIndex
        goIndex()
      })
    }
    //定时器实现自动播放
    setInterval(function () {
      gonext() //每5秒执行一次该函数
    }, 5000)
  },
}
</script>

<style lang="less" scoped>
.lunbo {
  position: relative;
}
.l-con {
  position: absolute;
  top: 0;
  left: 0;
}
div {
  display: flex;
}
li {
  list-style: none;
  text-align: center;
}
/*轮播图*/
.picture {
  /*大框架*/
  position: absolute;
  top: -350px;
  left: 100px;
  width: 1200px;
  height: 500px;
  margin-left: 190px;
  .btn {
    /*调整左右按钮*/
    position: absolute;
    top: 52%;
    width: 40px;
    height: 120px;
    background-color: rgba(0, 0, 0, 0);
    font-size: 60px;
    color: white;
    z-index: 100;
    border-radius: 10px;
  }
  #goPre {
    padding-left: 0;
    left: 40px;
    margin-top: -100px;
  }
  #goNext {
    padding-left: 5px;
    right: 160px;
    margin-top: -100px;
  }
  .lib {
    /*调整圆点外白框位置*/
    display: flex;
    justify-content: space-around;
    /*使圆点水平平分居中*/
    align-items: center;
    /*使圆点垂直居中*/
    position: absolute;
    bottom: 0;
    left: 0;
    right: 80px;
    margin: auto;
    /*使圆点的白框水平居中*/
    width: 300px;
    height: 30px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    z-index: 100;
    padding-right: 30px;
    li {
      /*调整圆点*/
      width: 20px;
      height: 20px;
      background: white;
      border-radius: 50%;

      cursor: pointer;
      /*将鼠标移动至点上变成手*/
    }
    .point.active {
      background: red;
    }
  }
  .pic li {
    /*display: none;*/
    position: absolute;
    /*使图片重合*/
    width: 100%;
    height: 350px;
    img {
      /*调整图片大小*/
      width: 1000px;
      height: 500px;
      margin-right: 300px;
    }
  }
}
/*轮播图点击效果*/
.item.active {
  /*初始时在有active的图片页*/
  z-index: 50;
}
.mid{
  position: absolute;
  top: 750px;
  left: 410px;
  img{
    width: 500px;
    height: 300px;
  }
}
.cont {
  position: absolute;
  display: block;
  top: 1050px;
  left: 410px;
  width: 1000px;
  height: 300px;
  background-color: #eee;
  div {
    display: block;
    .tco1 {
      color: rgb(43, 121, 238);
      text-align: center;
    }
    .tco2 {
      color: rgb(7, 51, 116);
      text-align: center;
    }
  }
}
.footer{
  position: absolute;
  top: 1300px;
  left: 410px;
  img{
    width: 333px;
  }
}
</style>
